;(function(FormBase) {
    FormBase.Chinese = FormBase.extend({
        singleConfig: {
            //需要区分多个金额表单 {formEleId : {} }
            defaultOption: {
                // allChinese: true, //是否全中文
                minLength: 2, //最小长度
                maxLength: 10, //最大长度
                maxLengthLimit: false, //超长是否限制输入
                errMsg: "ERR_Msg", //默认错误提示
                minLengthErrMsg: "MINLENGTH_ERRMSG", //最小长度默认错误提示
                maxLengthErrMsg: "MAXLENGTH_ERRMSG" //最大长度默认错误提示
            }
        },
        msgObj: { // error msg
            NOT_EMPTYP: "请输入姓名",
            ERR_Msg: "姓名必须为汉字",
            REAL_NAME_CN: "姓名必须为汉字",
            REALNAME_20: "姓名字符长度不正确",
            MINLENGTH_ERRMSG: "姓名字符长度不正确",
            MAXLENGTH_ERRMSG: "姓名字符长度不正确"
        },
        constructor: function(singleId, mainContent, formConfig) {

            this.inherit(singleId, mainContent, formConfig);
            //初始化 singleConfig
            !this.singleConfig[this.formEleId] && (this.singleConfig[this.formEleId] = {});
            this.singleConfig[this.formEleId] = $.extend({}, this.singleConfig.defaultOption, formConfig.singleConfig);
        },
        initMouseListeners: function() {
            if (document.all) { // IE
                this.formEle.attachEvent("onfocus", this.focusAction.bindAsEventListener(this));
                this.formEle.attachEvent("onblur", this.blurAction.bindAsEventListener(this));
                this.checkImmd && this.formEle.attachEvent("onpropertychange", this.changeAction.bindAsEventListener(this));

                //针对ie8实时处理
                this.checkImmd && this.isIE8() && this.formEle.attachEvent("onkeypress", this.keypressActionIE.bindAsEventListener(this));
                this.checkImmd && this.isIE8() && this.formEle.attachEvent("onkeyup", this.keyupActionIE.bindAsEventListener(this));
            } else {
                this.formEle.addEventListener("focus", this.focusAction.bindAsEventListener(this), false);
                this.formEle.addEventListener("blur", this.blurAction.bindAsEventListener(this), false);
                this.checkImmd && this.formEle.addEventListener("keydown", this.keydownAction.bindAsEventListener(this), false);
                this.checkImmd && this.formEle.addEventListener("keyup", this.keyupAction.bindAsEventListener(this), false);
                this.checkImmd && this.formEle.addEventListener("input", this.changeAction.bindAsEventListener(this), false);
            }
        },
        //针对IE8处理
        keypressActionIE: function(e) {
            var zz = /[0-9a-zA-Z.]*/;
            var txt = this.getCharFromKeyCode(e);
            if (zz.test(txt)) {
                this.alreadyHandle = true;
                return false;
            }
        },
        keydownAction: function(e) {
            this.alreadyHandle = true;
        },
        keyupAction: function(e) {
            if (!this.alreadyHandle) return;
            this.alreadyHandle = false;
            this.newValue = this.getEleValue(e);
            //中文输入进行处理
            if (this.newValue && !this.isIE8()) this.checkInputing();
            if (this.newValue) this.handleResult();
        },
        changeAction: function(e) {
            //如果IE8已经处理过了，跳过
            if (this.alreadyHandle) return;
            this.newValue = this.getEleValue(e);
            //中文输入进行处理
            if (this.newValue) this.handleResult();
        },
        susFun: function() {},
        errFun: function() {},
        checkInputing: function() {
            var reg = /[\u4e00-\u9fa5]+/; //1-20位中文
            this.newValue = reg.exec(this.newValue) ? (reg.exec(this.newValue)[0] ? reg.exec(this.newValue)[0] : reg.exec(this.newValue)) : "";
            this.formEle.value = this.formEle.value.replace(/[^\u4E00-\u9FA5]/g, '');
        },
        checkForm: function() {
            var singleConfig = this.getSingleConfig();
            var reg1 = /^[\u4e00-\u9fa5]+$/; //中文开头中文结尾，至少一位
            var reg = /[\u4e00-\u9fa5]{1,20}/; //1-20位中文
            if (this.limitInput) {
                if (this.newValue.length > 0) {
                    if (!reg1.test(this.newValue)) {　
                        return {
                            status: false,
                            msg: this.getMsg(singleConfig.errMsg),
                            value: reg.exec(this.newValue) ? reg.exec(this.newValue) : ""
                        };
                    } else if (this.newValue.length < singleConfig.minLength) {
                        return {
                            status: false,
                            msg: this.getMsg(singleConfig.minLengthErrMsg),
                            value: this.newValue
                        };
                    } else if (this.newValue.length > singleConfig.maxLength) {
                        return {
                            status: false,
                            msg: this.getMsg(singleConfig.maxLengthErrMsg),
                            value: this.newValue.substring(0, singleConfig.maxLength)
                        };
                    } else {
                        return {
                            status: true,
                            msg: null,
                            value: this.newValue
                        };
                    }
                } else {
                    return {
                        status: false,
                        msg: this.getMsg("NOT_EMPTYP"),
                        value: ""
                    };
                }
            } else {
                if (this.newValue.length > 0) {
                    if (!reg1.test(this.newValue)) {　
                        return {
                            status: false,
                            msg: this.getMsg(singleConfig.errMsg),
                            value: this.newValue
                        };
                    } else if (this.newValue.length < singleConfig.minLength) {
                        return {
                            status: false,
                            msg: this.getMsg(singleConfig.minLengthErrMsg),
                            value: this.newValue
                        };
                    } else if (this.newValue.length > singleConfig.maxLength) {
                        return {
                            status: false,
                            msg: this.getMsg(singleConfig.maxLengthErrMsg),
                            value: this.newValue
                        };
                    } else {
                        return {
                            status: true,
                            msg: null,
                            value: this.newValue
                        };
                    }
                } else {
                    return {
                        status: false,
                        msg: this.getMsg("NOT_EMPTYP"),
                        value: this.newValue
                    };
                }
            }

        }
    });
})(window.FormBase = window.FormBase || {})
